﻿using Lamp.Core.Client.Discovery;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;

namespace Lamp.Swagger
{
    public static class StartupExtension
    {
        public static IApplicationBuilder UseRpcSwagger(this IApplicationBuilder app, string version = "v1")
        {
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.InjectJavascript("/swagger/ui/zh_CN.js");
                c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"Rpc API {version}");
            });

            return app;
        }
        public static IServiceCollection UseRpcSwagger(this IServiceCollection services, RpcSwaggerOptions options, IClientServiceDiscovery clientServiceDiscovery)
        {
            services.AddSwaggerGen(c =>
            {
                c.CustomSchemaIds(type => type.FullName);
                c.SwaggerDoc(options.Version, new Info { Title = options.Title, Version = options.Version });
                c.DocumentFilter<RpcSwaggerDocumentFilter>(clientServiceDiscovery);
            });

            return services;
        }
    }
}
